<script>
    var switchId;
    function nextPage(pageNo){
        $("#notification-listing").load("<?= $this->baseURI(); ?>marketing/notification/list/0/"+pageNo);
    }
    function assignTeam(id){
        switchId = id;
        $("#add-notification-form").load("<?= $this->baseURI(); ?>marketing/notification/add/"+switchId);
        $("#add-notification-form" ).dialog( "open" );
    }
    function editTeam(id){
        switchId = id;
        $("#edit-notification-form").load("<?= $this->baseURI(); ?>marketing/notification/edit/"+switchId);
        $("#edit-notification-form" ).dialog( "open" );
    }
    function addFiles(switchId){
        
        $("#add-document-form").load("<?= $this->baseURI(); ?>marketing/notification/showfiles/"+switchId);
        $("#add-document-form" ).dialog( "open" );
    }
    $(function() {
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
        $( "#add-document-form" ).dialog({
            autoOpen: false,
            height: 300,
            width: 450,
            modal: true
        });
    });
    $(function() {
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
        $( "#add-notification-form" ).dialog({
            autoOpen: false,
            height: 300,
            width: 450,
            modal: true,
            buttons: {
                "Save": function() {
                    var bValid = true;
                    var price = $( "#contractPrice" );
                    var selectedUsers = $("#teamMembers").val() || [];
                    if ( bValid ) {
                        $.ajax({
                            type: "POST",
                            url: "<?= $this->baseURI(); ?>marketing/notification/add/"+switchId,
                            data: ({contractPrice : price.val(),teamMembers:selectedUsers.join(",")}),
                            success: function(msg){
                                $("#notification-listing").load("<?= $this->baseURI(); ?>marketing/notification/list");
                            }
                        });
                        $( this ).dialog( "close" );
                        $('#add-notification-form').html('');
                    }
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                    $('#add-notification-form').html('');
                }
            },
            close: function() {
                $('#add-notification-form').html('');
            }
        });


        $( "#edit-notification-form" ).dialog({
            autoOpen: false,
            height: 300,
            width: 450,
            modal: true,
            buttons: {
                "Save": function() {
                    var bValid = true;
                    var price = $( "#contractPrice" );
                    var selectedUsers = $("#teamMembers").val() || [];
                    if ( bValid ) {
                        $.ajax({
                            type: "POST",
                            url: "<?= $this->baseURI(); ?>marketing/notification/edit/"+switchId,
                            data: ({contractPrice : price.val(),teamMembers:selectedUsers.join(",")}),
                            success: function(msg){
                                $("#notification-listing").load("<?= $this->baseURI(); ?>marketing/notification/list");
                            }
                        });
                        $( this ).dialog( "close" );
                        $('#edit-notification-form').html('');
                    }
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                    $('#edit-notification-form').html('');
                }
            },
            close: function() {
                $('#edit-notification-form').html('');
            }
        });


    });
    function assignHouses(switchId){
        $("#add-house-form").load("<?= $this->baseURI(); ?>marketing/notification/houses/"+switchId);
        $(function() {
            $( "#dialog:ui-dialog" ).dialog( "destroy" );
            $( "#add-house-form" ).dialog({
                resize: false,
                width: 1000,
                modal: true                
            });
        });
    }
    function assignHouseUser(houseId,userId){
        inter = 0;
        id = $("#"+houseId+'-'+userId);
        if(id.is(':checked') ){
            inter = 1;
            $('input[name="'+houseId+'"]').attr("disabled",true);
            id.attr("disabled", false);
        }else{
            $('input[name="'+houseId+'"]').attr("disabled",false);
        }
        $.ajax({
            type: "POST",
            url: "<?= $this->baseURI(); ?>marketing/notification/assignhouses/"+houseId+"/"+userId,
            data: ({check : inter})
        });
    }
</script>
<div class="dataBoxOver">
    <div class="dataInnRep">
        <div class="dataInnTop" id="notification-listing">
            <?php echo $this->render('notification/list.phtml'); ?>
        </div>
    </div>
</div>
<div id="add-notification-form" title="Assign Team"></div>
<div id="add-house-form" title="Assign House"></div>
<div id="edit-notification-form" title="Edit"></div>
<div id="add-document-form" title="files"></div>